<template>
  <div>
    <van-nav-bar title="不凡乐购" left-text="返回" left-arrow @click-left="onClickLeft" class="navbar" />
    <div class="banner">
      <img :src="current.list_pic_url" alt />
      <div class="info">
        <span>{{current.name}}</span>
      </div>
    </div>
    <div class="info-desc">{{current.simple_desc}}</div>
    <!-- 根据goodslist长度，显示不同html -->
    <div class="none" v-if="goodsList.length == 0">数据库暂无数据....</div>
    <div class="sortlist" v-else>
      <div class="item" v-for="item in goodsList" :key="item.id">
        <img :src="item.list_pic_url" alt />
        <p class="name">{{item.name}}</p>
        <p class="price">￥{{item.retail_price}}</p>
      </div>
    </div>
  </div>
</template>

<script>
import { detailaction } from "@/api/nav";
export default {
  data() {
    return {
      current: [],
      goodsList: []
    };
  },
  created() {
    detailaction({
      id: this.$route.query.id
    }).then(res => {
      console.log(res);
      this.current = res.data;
      this.goodsList = res.goodsList;
    });
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    }
  }
};
</script>

<style lang="scss" scoped>
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 999;
}
.banner {
  width: 100%;
  height: 3.866667rem;
  position: relative;
  margin-top: 1.22667rem;
  img {
    width: 100%;
    height: 100%;
  }
  .info {
    text-align: center;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate3d(-50%, -50%, 0);
    span {
      font-size: 0.50667rem;
      color: #fff;
      border-bottom: 0.06667rem solid #fff;
      padding: 0.06667rem;
    }
  }
}
.info-desc {
  background: #fff;
  padding: 0.56rem 0.42667rem;
  font-size: 0.4rem;
  color: #666;
  text-align: center;
}
.none {
  text-align: center;
  color: #999;
  font-size: 0.42667rem;
  margin-top: 2.66667rem;
}
.sortlist {
  margin-top: 0.26667rem;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  .item {
    width: 4.96667rem;
    margin-bottom: 0.06667rem;
    text-align: center;
    background: #fff;
    padding: 0.2rem 0;
    img {
      display: block;
      width: 4.02667rem;
      height: 4.02667rem;
      margin: 0 auto;
    }
    .name {
      margin: 0.2rem 0 0.29333rem 0;
      text-align: center;
      padding: 0 0.26667rem;
      font-size: 0.32rem;
    }
    .price {
      text-align: center;
      font-size: 0.4rem;
      color: #b4282d;
    }
  }
}
</style>